package com.xunk.common.core.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @ProjectName: xunk
 * @Package: com.xunk.common.core.enums
 * @ClassName: DeviceEnum
 * @Author: yangwendong
 * @Description:
 * @Date: 2021/3/31 10:04
 * @Version: 1.0
 */
@AllArgsConstructor
@Getter
public enum RuyingDeviceEnum {
    RUYING_SMOKE_SENSOR("如影烟雾报警器", DeviceEnum.SMOKE_SENSOR, "urn:homekit-spec:device:smoke-sensor:0004000a:roomin:rcsyw01:1", "HS3SA", new HashMap<String, String>() {{
        put(".10.11", "detectedState");
        put(".10.14", "faultState");
        put(".17.18", "batteryLevel");
        put(".17.20", "lowBattery");
    }}),
    RUYING_WATER_SENSOR("如影水浸报警器", DeviceEnum.WATER_SENSOR, "urn:homekit-spec:device:water-sensor:0005000a:roomin:rcssj01:1", "CS03", new HashMap<String, String>() {{
        put(".10.11", "detectedState");
        put(".10.14", "faultState");
        put(".17.18", "batteryLevel");
        put(".17.20", "lowBattery");
    }}),
    RUYING_GAS_SENSOR("如影燃气报警器", DeviceEnum.GAS_SENSOR, "urn:homekit-spec:device:gas-sensor:0003000a:roomin:rcsrq01:1", "CS04", new HashMap<String, String>() {{
        put(".10.11", "detectedState");
        put(".10.14", "faultState");
        put(".17.18", "batteryLevel");
        put(".17.20", "lowBattery");
    }}),
    RUYING_DOOR_WINDOW_SENSOR("如影门窗传感器", DeviceEnum.DOOR_WINDOW_SENSOR, "urn:homekit-spec:device:door-window-sensor:0001000a:roomin:rcsmc01:1", "CS06", new HashMap<String, String>() {{
        put(".10.11", "detectedState");
        put(".10.14", "faultState");
        put(".17.18", "batteryLevel");
        put(".17.20", "lowBattery");
    }}),
    RUYING_GATEWAY("如影中控屏", DeviceEnum.GATEWAY, "urn:knowin-spec:device:gateway:00000001:know:insight:4", "insight", new HashMap<String, String>() {{
        // 中控屏暂时未推送数据
    }}),
    RUYING_WINDOW_CURTAIN("如影智能窗帘电机双层帘", DeviceEnum.WINDOW_CURTAIN, "urn:homekit-spec:device:window-covering:0000000e:roomin:rlcma01:1", "LCM01", new HashMap<String, String>() {{
        put(".10.11", "position");
        put(".10.12", "positionStatus");
        put(".10.13", "targetPosition");
        put(".14.15", "programMode");
        put(".14.16", "on");
    }}),
    RUYING_LIGHTBULB("如影智能驱动LED灯带版", DeviceEnum.LIGHTBULB, "urn:knowin-spec:device:lightbulb:00000005:know:kldq02:1", "LD02", new HashMap<String, String>() {{
        put(".10.11", "on");
        put(".10.12", "brightness");
        put(".10.13", "colorTemperature");
    }}),
    RUYING_ONE_KEY_SWITCH_BLACK("如影单键开关", DeviceEnum.ONE_KEY_SWITCH, "urn:homekit-spec:device:switch:00000008:know:klpj01b:1", "LP01B", new HashMap<String, String>() {{
        put(".10.11", "left.on");
    }}),
    RUYING_ONE_KEY_SWITCH_WHITE("如影单键开关", DeviceEnum.ONE_KEY_SWITCH, "urn:homekit-spec:device:switch:00000008:know:klpj01w:1", "LP01W", new HashMap<String, String>() {{
        put(".10.11", "left.on");
    }}),
    RUYING_TWO_KEY_SWITCH_BLACK("如影双键开关", DeviceEnum.TWO_KEY_SWITCH, "urn:homekit-spec:device:switch:00000008:know:klpj02b:1", "LP02B", new HashMap<String, String>() {{
        put(".10.11", "left.on");
        put(".13.14", "right.on");
    }}),
    RUYING_TWO_KEY_SWITCH_WHITE("如影双键开关", DeviceEnum.TWO_KEY_SWITCH, "urn:homekit-spec:device:switch:00000008:know:klpj02w:1", "LP02W", new HashMap<String, String>() {{
        put(".10.11", "left.on");
        put(".13.14", "right.on");
    }}),
    RUYING_THREE_KEY_SWITCH_BLACK("如影三键开关", DeviceEnum.THREE_KEY_SWITCH, "urn:homekit-spec:device:switch:00000008:know:klpj03b:1", "LP03B", new HashMap<String, String>() {{
        put(".10.11", "left.on");
        put(".13.14", "middle.on");
        put(".16.17", "right.on");
    }}),
    RUYING_THREE_KEY_SWITCH_WHITE("如影三键开关", DeviceEnum.THREE_KEY_SWITCH, "urn:homekit-spec:device:switch:00000008:know:klpj03w:1", "LP03W", new HashMap<String, String>() {{
        put(".10.11", "left.on");
        put(".13.14", "middle.on");
        put(".16.17", "right.on");
    }}),
    RUYING_AIR_CONDITIONER("如影中央空调智能控制网关", DeviceEnum.AIR_CONDITIONER, "urn:knowin-spec:device:air-conditioner:00000007:roomin:vrcgwk01:1", "vrcgwk01", new HashMap<String, String>() {{
        put(".2.1", "on");
        put(".2.2", "mode");
        put(".2.3", "temperature");
        put(".2.4", "targetTemperature");
        put(".2.5", "fanLevel");
        put(".2.6", "alarm");
    }}),
    RUYING_FRESH_AIR("如影新风机", DeviceEnum.FRESH_AIR, "urn:knowin-spec:device:fresh-air-system:00000003:hainayun:general:1", "XF01", new HashMap<String, String>() {{
        put(".2.1", "on");
        put(".2.2", "fanLevel");
    }}),
    UNKNOWN("未知设备", DeviceEnum.UNKNOWN, "Unknown", "Unknown", new HashMap<String, String>() {{
    }});

    String deviceName;
    DeviceEnum deviceEnum;
    String thirdType;
    String thirdSpec;
    Map<String, String> properties;

    private static final Map<String, RuyingDeviceEnum> THIRD_TYPE_ENUM_MAP = Arrays.stream(RuyingDeviceEnum.values()).collect(Collectors.toMap(RuyingDeviceEnum::getThirdType, Function.identity(), (a, b) -> a));

    public static RuyingDeviceEnum parseDeviceEnumByThirdType(String thirdType) {
        return THIRD_TYPE_ENUM_MAP.getOrDefault(thirdType, UNKNOWN);
    }

    private static final Map<DeviceEnum, RuyingDeviceEnum> DEVICE_TYPE_ENUM_MAP = Arrays.stream(RuyingDeviceEnum.values()).collect(Collectors.toMap(RuyingDeviceEnum::getDeviceEnum, Function.identity(), (a, b) -> a));

    public static RuyingDeviceEnum parseDeviceEnumByDeviceType(DeviceEnum deviceEnum) {
        return DEVICE_TYPE_ENUM_MAP.getOrDefault(deviceEnum, UNKNOWN);
    }
}
